/*
 * Copyright ©2021 su binglun(9085309@qq.com). All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *---------------------------------------------------------------------
 *-                                                                   -
 *-           Website : http://phoenix.sunny360.cn/                   -
 *-                                                                   -
 *---------------------------------------------------------------------
 */
package cn.sunny360.core.verticle;

import cn.sunny360.core.utils.Container;
import cn.sunny360.core.utils.FileUtils;
import io.vertx.core.*;
import io.vertx.core.impl.logging.Logger;
import io.vertx.core.impl.logging.LoggerFactory;
import io.vertx.core.json.JsonObject;

/**
 * Verticle基类，包含所有Verticle通用处理。
 * @author sublun
 */
public abstract class BaseVerticle extends AbstractVerticle {

    private static final Logger logger = LoggerFactory.getLogger(BaseVerticle.class);

    @Override
    public void init(Vertx vertx, Context context) {
        super.init(vertx, context);
        //初始化容器
        Container.init(vertx);
        vertx.exceptionHandler(exception->{
            exception.printStackTrace();
            logger.error("全局异常处理器捕获异常：", exception);
        });
    }

    protected <T extends Verticle> void deployVerticle(Class<T> verticle, DeploymentOptions options) {
        Future<String> future = vertx.deployVerticle(verticle.getName(), options);
        future.onSuccess(h->{
            logger.info("Verticle[" + verticle.getName() + "]develop success :" + h);
        }).onFailure(t->{
            logger.error("Verticle[" + verticle.getName() + "]develop failure.", t);
        });
    }
}
